package com.dm.service.impl;

import com.dm.dao.RecordDao;
import com.dm.dto.RecordDto;
import com.dm.dto.ResponseDto;
import com.dm.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hqw521@qq.com
 * @date 2018/11/30 15:54
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class RecordServiceImpl implements RecordService {
    @Autowired
    private RecordDao recordDao;

    @Override
    public ResponseDto<List<RecordDto>> findRecords(Integer page, Integer pageSize) {
        page = (page - 1) * pageSize;
        List<RecordDto> recordDtos = recordDao.findRecords(page, pageSize);
        Long totalCount = recordDao.selectCount();
        ResponseDto<List<RecordDto>> responseDto = new ResponseDto<>();
        responseDto.setTotalCount(totalCount);
        responseDto.setData(recordDtos);
        return responseDto;
    }
}
